<template>
  <div>
    <q-list bordered class="rounded-borders  no-shadow">
      <q-table
        class="bg-white shadow-1"
        :data="data"
        :columns="columns"
        dense
        row-key="id"
        separator="cell"
        :visible-columns="visibleColumns"
        :filter="searchForm"
        selection="multiple"
        :selected.sync="selected"
        :pagination.sync="pagination"
        :rows-per-page-options="[3, 5, 10, 20]"
        no-data-label="暂无数据"
        table-class="h-custom"
        @request="listGet"
      >
        <template v-slot:top-left="props">
          <div class="q-py-sm">
            <!-- <q-btn size="sm" color="light-blue" :label="$t('新增')"  @click.stop="add"/> -->
          </div>
        </template>
        <template v-slot:top-right="props">
          <q-select
            v-model="visibleColumns"
            multiple
            borderless
            options-dense
            :display-value="$t('显示列')"
            emit-value
            map-options
            :options="columns"
            option-value="name"
            class="q-mx-lg"
          >
            <template v-slot:option="scope">
              <q-item
                v-bind="scope.itemProps"
                v-on="scope.itemEvents"
                v-if="!scope.opt.required"
              >
                <q-item-section avatar>
                  <q-toggle color="blue" v-model="visibleColumns" :val="scope.opt.name" />
                </q-item-section>
                <q-item-section style="min-width:60px">
                  {{ scope.opt.label }}
                </q-item-section>
              </q-item>
            </template>
          </q-select>
          <q-toggle
            v-model="searchToggle"
            left-label
            label="搜索"
            color="blue"
            checked-icon="check"
            unchecked-icon="clear"
            keep-color
          />
          <q-btn
            flat round dense
            :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
            @click="props.toggleFullscreen"
            class="q-ml-md"
          />
        </template>
        <template v-if="searchToggle" v-slot:top-row="props">
          <q-tr :props="props">
            <q-td>
            </q-td>
            <q-td v-for="col in props.cols" :key="col.name" class="relative-position">
              <q-btn color="primary" dense flat icon="search" class="absolute-center" v-if="col.name==='action'" @click="listGet({ pagination: pagination, filter: searchForm })"/>
              <q-input dense outlined v-model="searchForm[col.name]" v-else/>
            </q-td>
          </q-tr>
        </template>
        <template v-slot:header="props">
          <q-tr :props="props">
            <q-th>
              <q-checkbox indeterminate-value="some" dense v-model="props.selected" />
            </q-th>
            <q-th v-for="col in props.cols" :key="col.name" :props="props">
              {{ col.label }}
            </q-th>
          </q-tr>
        </template>
        <template v-slot:body="props">
          <q-tr :props="props">
            <q-td width="52">
              <q-checkbox dense v-model="props.selected" />
            </q-td>
            <q-td key="action" :props="props">
              <q-btn-dropdown
                color="blue"
                size="sm"
                dense
                menu-anchor="bottom left"
                menu-self="top left"
                content-class="text-grey"
                icon="settings">
                <q-list dense>
                  <!-- <q-item clickable v-close-popup @click="edit(props.row)">
                    <q-item-section>
                      <q-item-label>修改</q-item-label>
                    </q-item-section>
                  </q-item> -->
                  <q-item clickable v-close-popup v-if="props.row.active === 0" @click="active(props.row, active=1)">
                    <q-item-section>
                      <q-item-label>启用</q-item-label>
                    </q-item-section>
                  </q-item>
                  <q-item clickable v-close-popup v-if="props.row.active === 1" @click="active(props.row, active=0)">
                    <q-item-section>
                      <q-item-label>禁用</q-item-label>
                    </q-item-section>
                  </q-item>
                  <!-- <q-item v-if="props.row.active == 0" clickable v-close-popup @click="active(props.row,actives = 1)">
                    <q-item-section>
                      <q-item-label>启用</q-item-label>
                    </q-item-section>
                  </q-item>
                  <q-item v-else clickable v-close-popup @click="active(props.row,actives = 0)">
                    <q-item-section>
                      <q-item-label>禁用</q-item-label>
                    </q-item-section>
                  </q-item> -->
                </q-list>
              </q-btn-dropdown>
            </q-td>
            <q-td key="vendorCode" :props="props">
              <span class="text-light-blue cursor-pointer">{{ props.row.vendorCode  }}</span>
            </q-td>
            <q-td key="vendorName" :props="props">{{ props.row.vendorName }}</q-td>
            <q-td key="active" :props="props">
              <q-chip dense square label="禁用" color="negative" text-color="white" v-if="props.row.active == '0'"/>
              <q-chip dense square label="启用" color="positive" text-color="white" v-if="props.row.active == '1'"/>
            </q-td>
            <q-td key="vendorItemCode" :props="props">{{ props.row.vendorItemCode  }}</q-td>
            <q-td key="vendorItemName" :props="props">{{ props.row.vendorItemName  }}</q-td>
            <q-td key="vendorSiteCode" :props="props">{{ props.row.vendorSiteCode  }}</q-td>
            <q-td key="vendorSiteName" :props="props">{{ props.row.vendorSiteName  }}</q-td>
            <!-- <q-td key="active" :props="props">
              <q-chip dense square label="启用" color="positive" text-color="white" v-if="props.row.type == '1'" />
              <q-chip dense square label="禁用" color="negative" text-color="white" v-if="props.row.type == '0'" />
            </q-td> -->
            <q-td key="createUserName" :props="props">{{ props.row.createUserName }}</q-td>
            <q-td key="createTime" :props="props">{{ props.row.createTime }}</q-td>
            <q-td key="remark"  :props="props" class="h-td-maxwidth ellipsis">
              {{ props.row.remark }}
              <q-popup-edit v-model="props.row.remark">
                <q-input type="textarea" v-model="props.row.remark" readonly dense autofocus counter />
              </q-popup-edit>
            </q-td>
          </q-tr>
          <q-tr v-show="props.expand" :props="props">
            <q-td colspan="100%">
            </q-td>
          </q-tr>
        </template>
        <template v-slot:pagination="props">
          <q-pagination
            v-model="pagination.page"
            color="blue"
            :max-pages="5"
            :max="pages"
            :boundaryLinks="true"
            :directionLinks="true"
          />
          共 {{ total }} 条
        </template>
      </q-table>
      <q-dialog
        v-model="addOrEditDialog"
        persistent
        :maximized="maximizedToggle"
        transition-show="slide-up"
        transition-hide="slide-down">
        <q-card class="bg-white relative-position" style="min-width: 40vw">
          <q-bar class="bg-white q-py-lg">
            <strong>{{ addOrEdit === 1? '新增' : '修改'}}</strong>
            <q-space />
            <q-btn dense flat icon="minimize" @click="maximizedToggle = false" :disable="!maximizedToggle">
              <q-tooltip v-if="maximizedToggle" content-class="bg-white text-primary">最小化</q-tooltip>
            </q-btn>
            <q-btn dense flat icon="crop_square" @click="maximizedToggle = true" :disable="maximizedToggle">
              <q-tooltip v-if="!maximizedToggle" content-class="bg-white text-primary">最大化</q-tooltip>
            </q-btn>
            <q-btn dense flat icon="close" @click="addOrEditDialog = false">
              <q-tooltip content-class="bg-white text-primary">关闭</q-tooltip>
            </q-btn>
          </q-bar>
          <q-separator />
          <q-card-section :style="maximizedToggle?'margin-bottom:53px;max-height:83.5vh': 'margin-bottom:53px;min-height:50vh;max-height:60vh'" class="scroll">
            <div class="row q-col-gutter-sm">
              <div class="col-12">
                <!-- <div :class="$v.addOrEditForm.vendorCode.$error?'text-negative': ''">供方编码</div> -->
                <div :class="$v.addOrEditForm.vendorName.$error?'text-negative': ''">供方名称</div>
                <q-input
                  disable
                  v-model="addOrEditForm.vendorName"
                  error-message="该字段为必填项"
                  :error="$v.addOrEditForm.vendorName.$error"
                  @blur="$v.addOrEditForm.vendorName.$touch"
                  dense hint >
                  <template v-slot:append>
                    <q-icon name="arrow_drop_down" />
                  </template>
                </q-input>
                <div  class="col-12" style="position: relative;top:-100px;height:100%" @click="venDialog = true"></div>
              </div>
              <div class="col-12">
                <div :class="$v.addOrEditForm.vendorCode.$error?'text-negative': ''">供方编码</div>
                <q-input
                  disable
                  v-model="addOrEditForm.vendorCode"
                  error-message="该字段为必填项"
                  :error="$v.addOrEditForm.vendorCode.$error"
                  @blur="$v.addOrEditForm.vendorCode.$touch"
                  dense hint/>
              </div>
              <div class="col-12">
                <div :class="$v.addOrEditForm.vendorItemCode.$error?'text-negative': ''">供方品项编码</div>
                <q-input
                  disable
                  v-model="addOrEditForm.vendorItemCode"
                  error-message="该字段为必填项"
                  :error="$v.addOrEditForm.vendorItemCode.$error"
                  @blur="$v.addOrEditForm.vendorItemCode.$touch"
                  dense hint >
                  <template v-slot:append>
                    <q-icon name="arrow_drop_down" />
                  </template>
                </q-input>
                <div  class="col-12" style="position: relative;top:-100px;height:100%" @click="siteDialog = true"></div>
              </div>
              <div class="col-12">
                <div :class="$v.addOrEditForm.vendorItemName.$error?'text-negative': ''">供方品项名称</div>
                <q-input
                  disable
                  v-model="addOrEditForm.vendorItemName"
                  error-message="该字段为必填项"
                  :error="$v.addOrEditForm.vendorItemName.$error"
                  @blur="$v.addOrEditForm.vendorItemName.$touch"
                  dense hint/>
              </div>
              <div class="col-12">
                <div :class="$v.addOrEditForm.vendorSiteCode.$error?'text-negative': ''">供方地点编码</div>
                <q-input
                  disable
                  v-model="addOrEditForm.vendorSiteCode"
                  error-message="该字段为必填项"
                  :error="$v.addOrEditForm.vendorSiteCode.$error"
                  @blur="$v.addOrEditForm.vendorSiteCode.$touch"
                  dense hint/>
              </div>
              <div class="col-12">
                <div :class="$v.addOrEditForm.vendorSiteName.$error?'text-negative': ''">供方地点名称</div>
                <q-input
                  disable
                  v-model="addOrEditForm.vendorSiteName"
                  error-message="该字段为必填项"
                  :error="$v.addOrEditForm.vendorSiteName.$error"
                  @blur="$v.addOrEditForm.vendorSiteName.$touch"
                  dense hint/>
              </div>
              <div class="col-12" style="">
                <div :class="$v.addOrEditForm.startTime.$error?'text-negative': ''">有效开始时间</div>
                <el-row  class="demo-input-suffix">
                  <el-date-picker
                  :id="$v.addOrEditForm.startTime.$error?'change':''"
                  :span="12"
                  :editable="editable"
                  size="large"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  v-model="addOrEditForm.startTime"
                  @blur="$v.addOrEditForm.startTime.$touch"
                  type="datetime"
                  placeholder="选择日期时间"
                  align="right">
                    <i slot="el-input__suffix" class="el-input__icon el-icon-search"></i>
                  </el-date-picker>
                </el-row>
                <div v-show="$v.addOrEditForm.startTime.$error" :class="$v.addOrEditForm.startTime.$error?'text-negative': ''">{{$v.addOrEditForm.startTime.required?'开始时间必须小于结束时间':'该字段为必填项'}}</div>
              </div>
              <div class="col-12">
                <div :class="$v.addOrEditForm.endTime.$error?'text-negative': ''">有效截止时间</div>
                  <el-row  class="demo-input-suffix">
                    <el-date-picker
                    value-format="yyyy-MM-dd HH:mm:ss"
                    :id="$v.addOrEditForm.endTime.$error?'change':''"
                    :span="12"
                    :editable="editable"
                    size="large"
                    format="yyyy-MM-dd HH:mm:ss"
                    v-model="addOrEditForm.endTime"
                    @blur="$v.addOrEditForm.endTime.$touch"
                    type="datetime"
                    placeholder="选择日期时间"
                    align="right">
                      <!-- <i slot="el-input__suffix" class="el-input__icon el-icon-search"></i> -->
                    </el-date-picker>
                  </el-row>
                <div v-show="$v.addOrEditForm.endTime.$error" :class="$v.addOrEditForm.endTime.$error?'text-negative': ''">{{$v.addOrEditForm.endTime.required?'结束时间必须大于开始时间':'该字段为必填项'}}</div>
              </div>
            </div>
          </q-card-section>
          <q-separator class="absolute" style="bottom: 52px; left: 0"/>
          <q-card-actions align="right" class="absolute-bottom bg-white">
            <q-btn flat label="取消" color="primary" v-close-popup />
            <q-btn flat label="保存" color="primary" :loading="loadingSave" @click="saveHandler" />
          </q-card-actions>
        </q-card>
      </q-dialog>
      <q-dialog
        v-model="venDialog"
        persistent
        :maximized="maximizedToggle"
        transition-show="slide-up"
        transition-hide="slide-down">
        <q-card class="bg-white relative-position" style="min-width: 50vw">
          <q-bar class="bg-white q-py-lg">
            <strong>{{ addOrEdit === 1? '选择供方品项' : '修改供方品项'}}</strong>
            <q-space />
            <q-btn dense flat icon="minimize" @click="maximizedToggle = false" :disable="!maximizedToggle">
              <q-tooltip v-if="maximizedToggle" content-class="bg-white text-primary">最小化</q-tooltip>
            </q-btn>
            <q-btn dense flat icon="crop_square" @click="maximizedToggle = true" :disable="maximizedToggle">
              <q-tooltip v-if="!maximizedToggle" content-class="bg-white text-primary">最大化</q-tooltip>
            </q-btn>
            <q-btn dense flat icon="close" @click="venDialog = false">
              <q-tooltip content-class="bg-white text-primary">关闭</q-tooltip>
            </q-btn>
          </q-bar>
          <q-separator />
          <q-card-section :style="maximizedToggle?'margin-bottom:53px;max-height:83.5vh': 'margin-bottom:53px;min-height:50vh;max-height:60vh'" class="scroll">
            <supplier-select-table url="/mdm/vendorMstr/query" @select="selectGetTab" :value="addOrEditForm.vendorId"></supplier-select-table>
          </q-card-section>
          <q-separator class="absolute" style="bottom: 52px; left: 0"/>
          <q-card-actions align="right" class="absolute-bottom bg-white">
            <q-btn flat label="取消" color="primary" v-close-popup  @click="returns"/>
            <q-btn flat label="保存" color="primary" :loading="loadingSave" @click="saveVen"/>
          </q-card-actions>
        </q-card>
      </q-dialog>
      <q-dialog
        v-model="siteDialog"
        persistent
        :maximized="maximizedToggle"
        transition-show="slide-up"
        transition-hide="slide-down">
        <q-card class="bg-white relative-position" style="min-width: 50vw">
          <q-bar class="bg-white q-py-lg">
            <strong>{{ addOrEdit === 1? '选择供方品项' : '修改供方品项'}}</strong>
            <q-space />
            <q-btn dense flat icon="minimize" @click="maximizedToggle = false" :disable="!maximizedToggle">
              <q-tooltip v-if="maximizedToggle" content-class="bg-white text-primary">最小化</q-tooltip>
            </q-btn>
            <q-btn dense flat icon="crop_square" @click="maximizedToggle = true" :disable="maximizedToggle">
              <q-tooltip v-if="!maximizedToggle" content-class="bg-white text-primary">最大化</q-tooltip>
            </q-btn>
            <q-btn dense flat icon="close" @click="siteDialog = false">
              <q-tooltip content-class="bg-white text-primary">关闭</q-tooltip>
            </q-btn>
          </q-bar>
          <q-separator />
          <q-card-section :style="maximizedToggle?'margin-bottom:53px;max-height:83.5vh': 'margin-bottom:53px;min-height:50vh;max-height:60vh'" class="scroll">
            <source-item :tenantId="addOrEditForm.vendorTenantId" @changeItem="groupItem"></source-item>
          </q-card-section>
          <q-separator class="absolute" style="bottom: 52px; left: 0"/>
          <q-card-actions align="right" class="absolute-bottom bg-white">
            <q-btn flat label="取消" color="primary" v-close-popup  @clock="removes"/>
            <q-btn flat label="保存" color="primary" :loading="loadingSave" @click="saveGroupItem"/>
          </q-card-actions>
        </q-card>
      </q-dialog>
    </q-list>
  </div>
</template>

<style lang="stylus" scoped>
  .h-td-maxwidth
    max-width 200px
  /deep/#change
    border-bottom 2px solid #c10015
  #name
    padding 0px
    border-radius 0
  /deep/.el-date-editor.el-input, .el-date-editor.el-input__inner
    width 100% !important
    padding-bottom 5px
  /deep/.el-input__inner
    border none
    border-radius 0
    border-bottom 1px solid #ccc
</style>

<script>

import { required } from 'vuelidate/lib/validators'
import SupplierSelectTable from 'components/Common/SupplierSelectTable'
import SourceItem from './SourceItem'
export default {
  name: 'Soure',
  components: {
    SupplierSelectTable,
    SourceItem
  },
  props: {
    selectSiteId: {}
  },
  data () {
    return {
      venDialog: false,
      editable: false,
      disable: false,
      confirm: false,
      siteDialog: false,
      errorCopy: false,
      searchToggle: false,
      searchForm: {
        vendorCode: '',
        vendorName: '',
        active: '',
        vendorItemCode: '',
        vendorItemName: '',
        vendorSiteCode: '',
        vendorSiteName: '',
        createTime: '',
        remark: ''
      },
      view: {},
      code: '',
      itemGroupOption: [],
      categoryOption: [],
      selected: [],
      visibleColumns: [
        'action',
        'vendorCode',
        'vendorName',
        'active',
        'vendorItemCode',
        'vendorItemName',
        'vendorSiteCode',
        'vendorSiteName',
        'createTime',
        'remark'
      ],
      // 当加入 required: true 属性时  visibleColumns 对当前字段无效
      columns: [
        { name: 'action', align: 'center', label: '操作' },
        { name: 'vendorCode', label: '供方编码', align: 'left', field: 'vendorCode', sortable: true },
        { name: 'vendorName', label: '供方名称', align: 'left', field: 'vendorName', sortable: true },
        { name: 'active', label: '状态', align: 'left', field: 'active', sortable: true },
        { name: 'vendorItemCode', required: true, label: '供方品项编码', align: 'left', field: 'vendorItemCode', sortable: true },
        { name: 'vendorItemName', required: true, label: '供方品项名称', align: 'left', field: 'vendorItemName', sortable: true },
        { name: 'vendorSiteCode', label: '供方地点编码', align: 'left', field: 'vendorSiteCode', sortable: true },
        { name: 'vendorSiteName', label: '供方地点名称', align: 'left', field: 'vendorSiteName', sortable: true },
        { name: 'createTime', field: 'createTime', align: 'left', label: '创建时间', sortable: true },
        { name: 'remark', field: 'remark', align: 'left', label: '说明', sortable: true }
      ],
      data: [
      ],
      total: 0,
      pagination: {
        page: 1,
        rowsPerPage: 10,
        rowsNumber: 10,
        sortBy: '',
        descending: Boolean
      },
      // dialog
      addOrEdit: 1, // 1 新增  2 修改
      loadingSave: false,
      addOrEditDialog: false,
      maximizedToggle: false,
      addOrEditTab: 'tab1',
      addOrEditForm: {
        id: '',
        itemSiteId: this.selectSiteId,
        vendorId: '',
        tenantId: '',
        vendorCode: '',
        vendorName: '',
        vendorItemSiteId: '',
        vendorItemCode: '',
        vendorItemName: '',
        vendorSiteCode: '',
        vendorSiteName: '',
        startTime: '',
        endTime: '',
        vendorTenantId: ''
      },
      siteId: ''
    }
  },
  // watch: {
  //   'selectSiteId' () {
  //     this.listGet()
  //   }
  // },
  computed: {
    pages () {
      return Math.ceil(this.total / this.pagination.rowsPerPage)
    }
  },
  validations: {
    addOrEditForm: {
      vendorCode: { required },
      vendorName: { required },
      vendorItemCode: { required },
      vendorItemName: { required },
      vendorSiteCode: { required },
      vendorSiteName: { required },
      startTime: {
        required,
        time () {
          let startDate = new Date(this.addOrEditForm.startTime)
          let endtDate = new Date(this.addOrEditForm.endTime)
          if (this.addOrEditForm.startTime !== '' && this.addOrEditForm.endTime !== '') {
            return startDate < endtDate
          } else {
            return true
          }
        }
      },
      endTime: {
        required,
        time () {
          let startDate = new Date(this.addOrEditForm.startTime)
          let endtDate = new Date(this.addOrEditForm.endTime)
          if (this.addOrEditForm.startTime !== '' && this.addOrEditForm.endTime !== '') {
            return endtDate > startDate
          } else {
            return true
          }
        }
      }
    }
  },
  watch: {
    'pagination.page' () {
      this.listGet({
        pagination: this.pagination,
        filter: this.searchForm
      })
    },
    'selectSiteId' () {
      this.listGet({
        pagination: this.pagination,
        filter: this.searchForm
      })
    }
  },
  mounted () {
    this.init()
    // this.getCode()
  },
  methods: {
    groupItem (row) {
      // console.log(row)
      this.addOrEditForm.vendorItemSiteId = row[0].id
      this.addOrEditForm.vendorItemCode = row[0].itemCode
      this.addOrEditForm.vendorItemName = row[0].itemName
      this.addOrEditForm.vendorSiteCode = row[0].siteCode
      this.addOrEditForm.vendorSiteName = row[0].siteName
    },
    saveGroupItem () {
      this.siteDialog = false
    },
    saveVen () {
      this.venDialog = false
    },
    removes () {
      this.addOrEditForm.vendorItemCode = ''
      this.addOrEditForm.vendorItemName = ''
      this.addOrEditForm.vendorSiteCode = ''
      this.addOrEditForm.vendorSiteName = ''
    },
    show () {
      this.init()
    },
    init () {
      this.listGet({
        pagination: this.pagination,
        filter: this.searchForm
      })
    },
    async listGet (props) {
      let { page, rowsPerPage, sortBy, descending } = props.pagination, filter = props.filter
      await this.$api({
        method: 'post',
        url: '/mdm/item/source/query',
        params: {
          pageNo: page,
          pageSize: rowsPerPage,
          sort: sortBy,
          order: descending === true ? 'desc' : (descending === false ? 'asc' : ''),
          ...filter
        },
        emulateJSON: true,
        useLoadLayer: true,
        successCallback: ({ data }) => {
          this.total = data.total
          this.data = data.list
        },
        errorCallback (err) {
          console.log('未处理的业务级error：', err)
        }
      })
      this.pagination.page = page
      this.pagination.rowsPerPage = rowsPerPage
      this.pagination.sortBy = sortBy
      this.pagination.descending = descending
    },
    add () {
      this.addOrEdit = 1
      this.addOrEditTab = 'tab1'
      this.addOrEditForm = {
        itemSiteId: this.selectSiteId,
        id: '',
        vendorId: '',
        tenantId: '',
        vendorCode: '',
        vendorName: '',
        vendorItemSiteId: '',
        vendorItemCode: '',
        vendorItemName: '',
        vendorSiteCode: '',
        vendorSiteName: '',
        startTime: '',
        endTime: '',
        vendorTenantId: ''
      }
      this.$v.addOrEditForm.$reset()
      this.addOrEditDialog = true
    },
    async edit (row) {
      console.log(row)
      this.addOrEditForm = {
        itemSiteId: row.selectSiteId,
        id: row.id,
        vendorId: row.vendorId,
        tenantId: row.tenantId,
        vendorCode: row.vendorCode,
        vendorName: row.vendorName,
        vendorItemSiteId: row.vendorItemSiteId,
        vendorItemCode: row.vendorItemCode,
        vendorItemName: row.vendorItemName,
        vendorSiteCode: row.vendorSiteCode,
        vendorSiteName: row.vendorSiteName,
        startTime: row.startTime,
        endTime: row.endTime,
        vendorTenantId: row.vendorTenantId
      }
      this.addOrEdit = 2
      this.addOrEditDialog = true
      this.addOrEditTab = 'tab1'
      this.$v.addOrEditForm.$reset()
    },
    async saveHandler () {
      console.log(this.addOrEditForm)
      this.$v.addOrEditForm.$touch()
      if (!this.$v.addOrEditForm.$error) {
        this.loadingSave = true
        await this.$api({
          method: 'put',
          url: this.addOrEdit === 1 ? '/mdm/item/source/add' : '/mdm/item/source/update',
          params: this.addOrEditForm,
          emulateJSON: true,
          useNotify: true,
          successCallback: ({ data }) => {
            if (this.addOrEdit === 1) {
              this.view = data
              this.confirm = true
            }
            this.addOrEditDialog = false
          },
          errorCallback (err) {
            console.log('未处理的业务级error：', err)
          }
        })
        this.listGet({
          pagination: this.pagination,
          filter: this.searchForm
        })
        // this.getCode()
        this.loadingSave = false
      } else {
        this.errorCopy = true
      }
    },
    active (row, actives) {
      console.log(row)
      let id = row.id
      let active = actives
      this.$q.dialog({
        message: `确认要启用/禁用：${row.vendorName} 吗？`,
        ok: true,
        cancel: true,
        persistent: true
      }).onOk(async () => {
        await this.$api({
          method: 'put',
          url: `/mdm/item/source/active/${id}/${active}`,
          emulateJSON: true,
          useNotify: true,
          successCallback: ({ data }) => {
            console.log(data)
          },
          errorCallback (err) {
            console.log('未处理的业务级error：', err)
          }
        })
        this.listGet({
          pagination: this.pagination,
          filter: this.searchForm
        })
      }).onCancel(() => {

      })
    },
    look (id) {
      this.$router.push({
        name: 'ItemPreview',
        params: { id }
      })
    },
    returns () {
      this.addOrEditForm.vendorId = ''
      this.addOrEditForm.tenantId = ''
      this.addOrEditForm.vendorCode = ''
      this.addOrEditForm.vendorName = ''
    },
    selectGetTab (row) {
      console.log('1111111111111111111111')
      this.addOrEditForm.vendorId = row[0].id
      this.addOrEditForm.vendorTenantId = row[0].vendorTenantId
      this.addOrEditForm.vendorCode = row[0].code
      this.addOrEditForm.vendorName = row[0].name
      console.log(this.addOrEditForm)
    }
  }
}
</script>
